package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program.geneSetAnalysis;

import java.util.Arrays;

/**
 * Holds string identifiers for a pair of gene sets
 * @author Jamie MacPherson
 */
class GeneSetPair {

    // ID for gene set 1
    private final String id1;

    // ID for gene set 2
    private final String id2;


    /**
     * The gene set ids that are passed to the constructor are first
     * sorted using their natural ordering and the field <code>id1</code>
     * takes the value of the first of the ordered ids and <code>id2</code>
     * takes the value of the second of the sorted ids. This sorting ensures
     * that two gene sets are equal if their id1 and id2 fields are diectly compared.
     * @param id1 gene set 1
     * @param id2 gene set 2
     */
    public GeneSetPair(String id1, String id2) {
        String arr[] = {id1, id2};
        Arrays.sort(arr);

        this.id1 = arr[0];
        this.id2 = arr[1];
    }

    /**
     * @return the id1 field, an identifier for the first gene set.
     */

    public String getId1() {
        return id1;
    }

    /**
     * @return the id2 field, an identifier for the second gene set.
     */
    public String getId2() {
        return id2;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final GeneSetPair other = (GeneSetPair) obj;
        if ((this.id1 == null) ? (other.id1 != null) : !this.id1.equals(other.id1)) {
            return false;
        }
        if ((this.id2 == null) ? (other.id2 != null) : !this.id2.equals(other.id2)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 29 * hash + (this.id1 != null ? this.id1.hashCode() : 0);
        hash = 29 * hash + (this.id2 != null ? this.id2.hashCode() : 0);
        return hash;
    }


}
